package com.uploadtest.jiaotizhixing;

public class SyncNotifyWaitTest {
    public static void main(String[] args) {
        final char arrayA[] = "1234567".toCharArray();
        final char arrayB[] = "ABCDEFG".toCharArray();
        Object o = new Object();
        Runnable runnable = () -> {
            synchronized (o) {
                for (char charA : arrayA) {
                    System.out.print(charA);
                    try {
                        o.notify();
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                o.notify();
            }
        };
        Runnable runnable1 = () -> {
            synchronized (o) {
                for (char charB : arrayB) {
                    try {
                        System.out.print(charB);
                        o.notify();
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                o.notify();
            }
        };
        new Thread(runnable).start();
        new Thread(runnable1).start();
    }
 
}